﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using Models;
using System.Configuration;
namespace AGVControlSystemPro
{
    public partial class FrmWatchBoard : Form
    {
        RemoteIOManager objRemoteIOManager = new RemoteIOManager();
        private int remoteIOCount = 0;
        public FrmWatchBoard()
        {
            InitializeComponent();
            this.dgvFinishCall.AutoGenerateColumns = false;
            this.dgvStandbyCall.AutoGenerateColumns = false;
            new Common.DataGridViewStyle().DgvStyle3(this.dgvStandbyCall);
            new Common.DataGridViewStyle().DgvStyle4(this.dgvFinishCall);
            this.timReflsh.Start();
            this.timer1.Start();
            this.remoteIOCount =Convert.ToInt32( ConfigurationManager.AppSettings["RemoteIOCount"]);//远程IO个数
        }

        private void FrmWatchBoard_Load(object sender, EventArgs e)
        {

        }
        public void Receiver(WatchBoards objWatchBoard)
        {
            this.lblAGVIn.Text = objWatchBoard.AGVOnlineCount.ToString();
            this.lblAGVOut.Text = objWatchBoard.AGVOutCount.ToString();
            this.lblCallIn.Text = objWatchBoard.RemoteIOCount.ToString();
            this.lblCallOut.Text = (remoteIOCount - objWatchBoard.RemoteIOCount).ToString();
        }
        private void FrmWatchBoard_FormClosed(object sender, FormClosedEventArgs e)
        {
            FrmMain.objFrmWatchBoard = null;
        }
        private void UnfinishCallShow()
        {
            this.dgvStandbyCall.DataSource = null;
            this.dgvStandbyCall.DataSource = objRemoteIOManager.GetUnfinishCallByTime(DateTime.Now);
            this.lblCall.Text = this.dgvStandbyCall.Rows.Count.ToString(); //显示为完成
        }
        private void FinishCallShow()
        {
            this.dgvFinishCall.DataSource = null;
            this.dgvFinishCall.DataSource = objRemoteIOManager.GetFinishCallByTime(DateTime.Now);
            this.lblCallFinish.Text = this.dgvFinishCall.Rows.Count.ToString();
        }
        private void timReflsh_Tick(object sender, EventArgs e)
        {
            
            UnfinishCallShow();
            FinishCallShow();
        }

        private void dgvStandbyCall_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Common.DataGridViewStyle.DgvRowPostPaint(this.dgvStandbyCall,e);
        }

        private void dgvFinishCall_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Common.DataGridViewStyle.DgvRowPostPaint(this.dgvFinishCall,e);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.lblTime.Text = DateTime.Now.ToString();
        }

    }
}
